package com.sesurity.service.Impl;

import com.sesurity.domain.LoginUser;
import com.sesurity.domain.User;
import com.sesurity.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

@Service
public class UserDetailsServiceImpl implements UserDetailsService {



    @Autowired
    private UserMapper userMapper;

    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        User user = userMapper.queryUserByUserName(username);
        System.out.println("运行到这里");
        System.out.println(user);
        if (user==null){
            throw new RuntimeException("用户名不存在");
        }
        LoginUser loginUser = new LoginUser(user);
        return loginUser;
    }


}
